package com.bops.valve.webuser;

import java.util.ArrayList;
import java.util.List;

import com.bops.biz.permission.UserGrant;

public class BopsWebUser {

    /**
     */
    private static ThreadLocal<BopsWebUser> userHolder       = new ThreadLocal<BopsWebUser>();

    public static BopsWebUser getCurrentUser() {
        return userHolder.get();
    }

    static void setCurrentUser(BopsWebUser webUser) {
        userHolder.set(webUser);
    }

    /** ----------以下是WebUser的成员属性------------- */
    private String  name; //用户名
    private String  role;
    private Integer memberId;
    private boolean hasLogin;
    private List<String> roleList;
    private UserGrant userGrant;
    
    public UserGrant getUserGrant() {
        return userGrant;
    }
    
    public void setUserGrant(UserGrant userGrant) {
        this.userGrant = userGrant;
    }

    /**
     * 判断是否有权限
     * @param roleId
     * @return
     */
    public boolean hasPermission(String roleId)
    {
        if (userGrant==null)
        {
            return false;
        }
        return userGrant.hasPermission(roleId);
    }
    /**
     * 返回该用户拥有的Role
     * @return
     */
    public List<String> getRoleList()
    {
        if (roleList==null)
        {
            roleList = new ArrayList<String>();
            if (role!=null)
            {
                String s[] = role.split("\\|");
                for (String t:s)
                {
                    roleList.add(t);
                }
            }
        }
        return roleList;
    }
    
    public String getRole() {
        return role;
    }
    
    public void setRole(String role) {
        this.role = role;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    
    public boolean isHasLogin() {
        return hasLogin;
    }

    public Integer getMemberId() {
        return memberId;
    }

    public boolean hasLogin() {
        return hasLogin;
    }

    void setMemberId(Integer memberId) {
        this.memberId = memberId;
    }

    void setHasLogin(boolean hasLogin) {
        this.hasLogin = hasLogin;
    }
    public void setRoleList(List<String> roleList) {
        this.roleList = roleList;
    }
    
}
